package com.xsr.controller;

import com.alibaba.fastjson.JSON;
import com.xsr.pojo.GoodsType;
import com.xsr.service.GoodsTypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project xiaomi
 * @date 2022/9/13 20:35
 */
@RestController
@RequestMapping("/goodstypeservlet")
public class GoodsTypeController {
    @Autowired
    private GoodsTypeService goodsTypeService;
 @RequestMapping("/goodstypelist")
    public String SelectGoodsType(HttpServletRequest request){

        String json =(String) request.getServletContext().getAttribute("goodstype");
        if(json==null) {

            List<GoodsType> goodsTypes = goodsTypeService.findByLevel(1);
            json = JSON.toJSONString(goodsTypes);
            request.getServletContext().setAttribute("goodstype",json);
            System.out.println("访问数据库");
     return json;
        }


      return json;
    }
    };

